package middleware

import "context"

type Handler func(ctx context.Context, req any) (any, error)

type Middleware func(Handler) Handler

// Chain returns a Middleware that specifies the chained handler for endpoint.
// Middleware按先后顺序执行，则最先的Mid包裹较后的Mid，其暴露在最外
func Chain(m ...Middleware) Middleware {
	return func(next Handler) Handler {
		for i := len(m) - 1; i >= 0; i-- {
			next = m[i](next)
		}
		return next
	}
}
